package com.tianma.upload.uploadjartest.proxy.cglib;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @author lgc
 * @createDate 2020/8/13 - 16:23
 */
public class CglibProxyUtils<T> {
     public  T getProxyObject(T target){
         Object o = Enhancer.create(target.getClass(), new InvocationHandler() {
             @Override
             public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                 if (method.getName().equals("sent")){
                     Integer i =(int) objects[0];
                     i+=200;
                     return method.invoke(target,i);
                 }
                 return method.invoke(target,objects);
             }
         });
         return (T)o;
     }
}
